import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/reset.css'
import 'element-ui/lib/theme-chalk/index.css'
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
import Vue from 'vue'
import App from './App'
import router from './router'
import VueQuillEditor from 'vue-quill-editor'
import api from './apis/api'
import Vuex from 'vuex'
import store from './store/store'
import './assets/iconfont/iconfont.css'
import infiniteScroll from 'vue-infinite-scroll'
import VueClipboard from 'vue-clipboard2'
import touch from 'vue-directive-touch'
import vueSocketIo from 'vue-socket.io'
import {fetch} from './utils/httpRequest'
import './utils/directives.js';

Vue.config.productionTip = false
Vue.use(ElementUI)
Vue.use(VueQuillEditor);
Vue.use(Vuex)
Vue.use(infiniteScroll)
Vue.use(VueClipboard)
Vue.use(touch)
Vue.prototype.http = api;
var vue=new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
})
// 登录之后再链接上推送接口
if(store.getters.loginData.session_id){
  fetch(api.message.getTcpServerList,{}).then((response)=>{
    if(response.success){
      //动态获取TCP消息推送服务列表并随机挑选一个服务链接
      Vue.use(new vueSocketIo({
        debug: true,
        connection: 'http://'+response.data[Math.floor(Math.random()*response.data.length+0)]+"?token="+store.getters.loginData.session_id,
        vuex: {
          store,
          mutationPrefix: "SOCKET_",
          actionPrefix: "SOCKET_"
        }
      }));
      vue.$socket.emit('receive_event', {'content':'connect'})
    }
  })
}